<?php

class Style
{
	public $Object = array( );
	
	public function __construct( $Style = false )
	{
		if( !!$Style ) $this->Load( $Style );
	}
	
	public function Get( $Key )
	{
		$Key = strtolower( $Key );
		return $this->Object[ $Key ];
	}
	
	public function Set( $Key, $Value )
	{
		$Key = strtolower( $Key );
		return $this->Object[ $Key ] = $Value;
	}
	
	public function __get( $Key )
	{
		return $this->Get( $Key );
	}
	
	public function __set( $Key, $Value )
	{
		return $this->Set( $Key, $Value );
	}
	
	public function Clear( )
	{
		$this->Object = array( );
	}
	
	public function Load( $Style )
	{
		$StylePropertiesArray = explode( ';', $Style );
		foreach( $StylePropertiesArray as $StylePropertyString )
		{
			$StylePropertyArray = explode( ':', $StylePropertyString );
			if( count( $StylePropertyArray ) > 1 )
			{
				$Key = $StylePropertyArray[0];
				$Value = $StylePropertyArray[1];
				$this->$Key = $Value;
			}
		}
	}
	
	public function GetStyle( )
	{
		$StylePropertiesArray = array( );
		foreach( $this->Object as $Key => $Value )
		{
			$StylePropertiesArray[] = $Key . ':' . $Value;
		}
		return implode( ';', $StylePropertiesArray );
	}
	
	public function Render( )
	{
		print 'style="' . $this->GetStyle( ) . '"';
	}
}
